﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RazorTemplateEngine
{
    /// <summary>
    /// This is the base class which the dynamic generated class will inherit from,
    /// and the TemplatePageRazorHost define the class name, see TemplatePageRazorHost.DefaultBaseClass
    /// for more infomation
    /// </summary>
    public class __TemplatePage : RazorPage
    {
        /// <summary>
        /// Store the parse result
        /// </summary>
        private StringBuilder resultBuilder = new StringBuilder();
        /// <summary>
        /// Store the data passed from controller
        /// </summary>
        private Dictionary<string, object> templateData = new Dictionary<string, object>();


        public override StringBuilder ParseResult
        {
            get { return resultBuilder; }
        }
        public override Dictionary<string, object> TemplateData
        {
            get { return templateData; }
            set { templateData = value; }
        }

        /// <summary>
        /// implement method in the dymanic generated class , the method name is defined in 
        /// GeneratedClassContext.DefaultWriteLiteralMethodName in System.Web.Razor
        /// </summary>
        /// <param name="literal"></param>
        public override void WriteLiteral(string literal)
        {
            resultBuilder.Append(literal);
        }

        /// <summary>
        /// implement method in the dymanic generated class , the method name is defined in 
        /// GeneratedClassContext.DefaultWriteMethodName in System.Web.Razor
        /// </summary>
        /// <param name="obj"></param>
        public override void Write(object obj)
        {
            resultBuilder.Append(obj.ToString());
        }

        private string _layout;

        public override string Layout
        {
            get { return _layout; }
            set {
                _layout = value;
            }
        }

        public override string ChildBody { get; set; }

        public override string RenderBody()
        {
            if(ChildBody != null)
                return ChildBody;
            return string.Empty;
        }
    }
}
